<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%> 
<div  class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'资料查询',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>资料名称</span></td>
				<td class="screen-n">
					<input type="text" id="fileName" class="screen-input" onkeydown="pms.kd13('initTable')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initTable()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    
    
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
 
 
</div> 
<script type="text/javascript">
var tb;
var toolbar = [
<se:hasPermissions actCode="ADD" >     
{
	text:'上传资料',
    iconCls:'ext-icon-note_add',
    handler:function(){
    	uploader();
    }
},
</se:hasPermissions>          
<se:hasPermissions actCode="DELETE" >
{
	text:'删除资料',
    iconCls:'ext-icon-key',
    handler:function(){
    	removeFile();
    }
}
</se:hasPermissions>
]; 
function getParams(){
	var queryParamss = {
			"moduleId": 'sys',
			"funcId" : 'web',
			"dataId" : 'information',
			"fileName":$('#fileName').val()
	    };
    return queryParamss;
}
function initTable(){
	tb = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
	    columns:[[
	              {field:'ck',checkbox:true},
	              {field:'uploadId',title:'ID',align:'center'},
	              {field:'viewsmall',title:'图标',align:'center',formatter:function(value,rows){
		                if(rows.fileType =="img"){
							return '<a href="'+contentPath+rows.relativeFilePath+"/"+rows.fileSysName+'" target="_blank" ><span style="padding:1px;"><img src="'+contentPath+rows.relativeFilePath+"/small_"+rows.fileSysName+'" width="30px;" height="30px;"  /></span></a>';
		                }else if(rows.fileType =="file"){
		                	return '<span style="padding:1px;"><img src="'+contentPath+rows.fileIcons+'" width="30px;" height="30px;" /></span>';
			            }else if(rows.fileType =="all"){
							//未存类型
			            	return '<span style="padding:1px;"><img src="'+contentPath+rows.fileIcons+'" width="30px;" height="30px;" /></span>';
				        }
				  }},
	              {field:'fileName',title:'文件名',align:'center'},
	              {field:'fileExtensions',title:'后缀',align:'center'},
	              {field:'fileSizeKb',title:'大小',align:'center'},
	              {field:'creationDate',title:'上传时间',align:'center'},
	              {field:'relativeFilePath',title:'目录',align:'center'},
	              {field:'fileSysName',title:'存储名',align:'center'},
	              {field:'action',title:'操作',align:'center',formatter:function(value,rows){
						return '<a href="'+contentPath+rows.relativeFilePath+"/"+rows.fileSysName+'" target="_blank">下载</a>';
		          }}
	              
	          ]],
	    url:'<c:url value="/upload/searchPageEmBUpload.do"/>',  
	    pagination:true,//分页控件
	    pageSize:30,
	    queryParams:getParams(),
		singleSelect:false,
		onLoadSuccess : function(data) {
			var panel = $(this).datagrid('getPanel');
			var tr = panel.find('div.datagrid-body tr');
			tr.each(function() {
				var td = $(this).children('td[field="fileName"]');
				td.children("div").css({
					"text-align" : "left"
				});
			});
			tr.each(function() {
				var td = $(this).children('td[field="relativeFilePath"]');
				td.children("div").css({
					"text-align" : "left"
				});
			});
			tr.each(function() {
				var td = $(this).children('td[field="fileSysName"]');
				td.children("div").css({
					"text-align" : "left"
				});
			});
		}
	}); 
}

$(function(){
	initTable();
});

function removeFile() {
	var row = $('#tableGrid').datagrid('getSelections');
	if (row) {
		$.messager.confirm('确认', '您确定需要删除该条记录吗？', function(r) {
			var ids = '';
			for ( var i = 0; i < row.length; i++) {
				if (i == row.length - 1) {
					ids += row[i].uploadId;
				} else {
					ids += row[i].uploadId + ',';
				}
			}
			if (r) {
				$.ajax({
					type : "POST",
					url : "<c:url value='/upload/deleteMultipleEmBUpload.do'/>",
					data : 'uploadIdList=' + ids.toString(),
					success : function(data) {
						if (data.success) {
							alertShow("删除成功");
							tb.refresh();
						} else {
							alertError("删除失败");
						}
					}
				});
			}
		});
	} else {
		alertWarning('请选择一条数据！');
	}
}
function  uploader(){
	$.pmsDialog({
		id:"plug_upload",  //固定ID
		title:'上传资料',
		isIf:'true',
		params:{    //这4个必须填   可
    		"fileType":"all", //必填项  file  or  img or all
    		"oneSelect":'true',
    		"moduleId": 'sys',
			"funcId" : 'web',
			"dataId" : 'information'
    	},
		method:'post',
		href:'<c:url value="/views/jsp/upload/com_uploader_s.jsp"/>',
		width:600,
		height:464
	});
}
function getFiles(obj){
	if(obj!='undefined'){
		$('#smallPicName').html("<img src='"+contentPath+obj[0].relativeFilePath+"small_"+obj[0].fileSysName+"' width='30px;' height='30px;' />");
		$('#smallPic').val(obj[0].relativeFilePath+"small_"+obj[0].fileSysName);
		$('#uploadId').val(obj[0].id);
		alertShow("选择图片成功!");
	}
}
//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/upload/searchPageWebImformationExcel.do"/>',getParams());
} 
</script>
